<template>
  <div class="container">
    <globalHeader :user="currentUser" />
    <loader v-if="isLoading" text="拼命加载中" background="rgba(0,0,0,.8)" ></loader>
    <!-- <login/>
    <home/> -->
    <router-view ></router-view>
    <footer class="text-center py-4 text-secondary bg-light mt-6">
      <small>
        <ul class="list-inline mb-0">
          <li class="list-inline-item">© 2021 阅读者专栏</li>
          <li class="list-inline-item">课程</li>
          <li class="list-inline-item">文档</li>
          <li class="list-inline-item">联系</li>
          <li class="list-inline-item">更多</li>
        </ul>
      </small>
    </footer>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed, onMounted, watch } from 'vue'
import 'bootstrap/dist/css/bootstrap.min.css'
import GlobalHeader from './components/GlobalHeader.vue'
import createMessage from './components/createMessage'
import Loader from './components/Loader.vue'
import { useStore } from 'vuex'
import { GlobalDataProps } from './store'

export default defineComponent({
  name: 'App',
  components: {
    GlobalHeader,
    Loader
    // Home,
    // Login
  },
  setup () {
    const store = useStore<GlobalDataProps>()
    const isLoading = computed(() => store.state.loading)
    const currentUser = computed(() => store.state.user)
    const error = computed(() => store.state.error)
    watch(() => error.value.status, () => {
      const { message, status } = error.value
      if (status && message) {
        createMessage(message, 'error', 2000)
      }
    })
    // onMounted(() => {
    //   if (localStorage.getItem('token')) {
    //     store.dispatch('fetchCurrentUser', { token: localStorage.getItem('token') })
    //   }
    // })
    return {
      currentUser,
      isLoading,
      error
    }
  }
})
</script>

<style>
</style>
